package org.goldenport.g3.jetty

//import javax.servlet.http.HttpServletRequest
//import javax.servlet.http.HttpServletResponse
//import javax.servlet.ServletConfig
//import javax.servlet.ServletException
//import java.io.IOException
//import org.eclipse.jetty.websocket.WebSocket
//import org.eclipse.jetty.websocket.WebSocket._
//import org.eclipse.jetty.websocket.WebSocketServlet
import org.goldenport.g3._
import org.goldenport.g3.messages._
import org.goldenport.g3.events.Posted
import org.goldenport.g3.adapters._

/**
 * @since   Nov. 21, 2010
 * @version Nov. 28, 2010
 * @author  ASAMI, Tomoharu
 */
class JettyWebSocketDriver() extends G3WebSocketDriver {
  protected def new_Agent(cmd: G3Command, ctx: G3AgentContext): G3WebSocketDriverAgent = new JettyWebSocketDriverAgent(cmd.uri, ctx)
}

class JettyWebSocketDriverAgent(uri: String, ctx: G3AgentContext) extends G3WebSocketDriverAgent(uri, ctx) {
  @Override
  def post(post: Post): G3Event = {
    val text = post.asText
    println("WebSocketDriver post = " + uri + "/" + text)
    JettyWebSocketConnections.sendMessage(uri, text)
    Posted(post.uri, text)
  }
}
